//
//  WWSameSickCell.m
//  快医
//
//  Created by 孙博 on 16/7/7.
//
//

#import "WWSameSickCell.h"

@interface WWSameSickCell ()

@property (nonatomic, weak)UIButton *btn;

@end

@implementation WWSameSickCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return  self;
}

- (void)setModel:(WWSameSickModel *)model{
    _model = model;
    
    self.textLabel.text = model.title;
    
    self.btn.selected = model.taped;
}

#pragma
#pragma mark -设置cell内容
- (void)setupUI{
    self.textLabel.text = _model.title;
    
    UIButton *btn = [[UIButton alloc]init];

    
    self.btn = btn;
    
    [self.contentView addSubview:btn];
    btn.backgroundColor = XHRThemeColor;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    [btn setTitle:@"订阅" forState:UIControlStateNormal];
    [btn setTitle:@"已订阅" forState:UIControlStateSelected];
    
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];

    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(-10);
        make.centerY.equalTo(self.centerY);
        make.width.equalTo(60);
        make.height.equalTo(30);
    }];
}

- (void)clickBtn:(UIButton *)sender{

    sender.selected = !sender.isSelected;
    
    if (self.changeBlock) {
        self.changeBlock();
    }
}

@end
